<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const nums = [1, 3, 5, 6]
        function fn(nums,target) {
            for (let i = 0; i < nums.length; i++) {
                if(nums[i] >= target){ 
                    return i
                }
            }
            return   nums.length
        }
        fn(nums,7)

        console.log(fn(nums,7));

        // 二分法
        function fn3 (nums,taeget) {
            let totallen = nums.length;
            if(taeget < nums[0]){
                return 0
            }
            if(taeget > nums[totallen - 1 ]){
                return totallen
            }

            let leftIndex = 0;
        
        } 


    </script>
    <!-- <script>
        const nums = [1, 2, 3, 5, 10]

       function fn (nums,target){
             nums.push(target)
             nums.sort((a,b) => a - b)
             console.log(nums);
          for(let i=0;i < nums.length; i++){
              if(nums[i] === target){
                  return i
              }
          }
      
    
            // for (let i = 0; i < nums.length; i++) {
            //     if (nums[i] === target) {
            //         return i

            //     }
            // }
        };
        fn(nums,2)
  console.log(fn(nums,2));
    </script> -->
</body>

</html>